<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<% String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/fmt.tld" prefix="fmt" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>启用授信信息</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
	<div class="Wrapper">
		<div>
			<form id="crBaseInfo">
				<div class="fieldset1 tabel_col clearFix">
					<div class="fieldBox col_100_auto">
						<div class="label">授信有效期</div>
						<div class="field">
			                <input name="stDt" id="stDt" type="text" class="ui-datepicker" value="" validate="{required:true}"><span >&nbsp;至&nbsp;</span>
			                <input name="edDt" id="edDt" type="text" class="ui-datepicker" value="" validate="{required:false}">
			            </div>
					</div>
    			</div>
				<div class="btnsBox">
					<span id="saveCrBaseBtn" class="sq-button sq-button-round">确定</span>
					<input type="reset" id="resetBtn" class="l-button l-button-reset Hide">
   				</div>
			</form>
		</div>
	</div>
	<script type="text/javascript">
	 $(function () {
	        $("#crBaseInfo").ligerForm({
	            validate: true
	        });
			//加载日期插件
			$("#stDt").trigger("change");
			$("#edDt").trigger("change");
			
	        //设置开始时间字段不可编辑
	        liger.get("stDt").setDisabled(true);
	        
			//设置表单数据
			if('${crBaseInfoVo}' != null){
				if('${crBaseInfoVo.stDt}' != ''){//开始时间
			    	liger.get("crBaseInfo").setData({
			    		stDt: renderDateChange('${crBaseInfoVo.stDt}')
			    	});
				}
				if('${crBaseInfoVo.edDt}' != ''){//结束时间
			    	liger.get("crBaseInfo").setData({
			    		edDt: renderDateChange('${crBaseInfoVo.edDt}')
			    	});
				}
			}
	        
	        //保存：新增-修改
	        $("#saveCrBaseBtn").click(function (event) {
	            var form = liger.get("crBaseInfo");
	            if (!form.valid()) {
	                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
	                return false; //验证不通过，不执行以下代码
	            }
	            var data = form.getData();
	            data["id"] = "${id}";
	            data["flag"] = "${flag}";
	            $.ligerDialog.hide();
	            var _url = '<%=path%>/rfbase/crbaseinfo/switchCrRecord.do';
	            var wait_dialog = null;
	            $.ajax({
	                type: 'post',
	                dataType: 'json',
	                data: data,
	                url: _url,
	                beforeSend: function () {
	                    wait_dialog = top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
	                },
	                success: function (msg) {
	                    wait_dialog.close();
	                    if (msg.success == 1) {
	                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
	                        //刷新授信列表
	                        parent.window.location.href="<%=path%>/rfbase/crbaseinfo/toListPage.do?";
	                        frameElement.dialog.close();
	                    } else {
	                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
	                    }
	                }
	            });
	        });
	    });
	 
		//格式化时间
		function renderDateChange(value){
			var dateStr = "";
			if(null != value &&  "" != value){
				var date = new Date(value);
				dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
			}
			return dateStr;
		}

	</script>
</body>
</html>